import cityjs from "@/pages/city/cityjs.js";
// import $t from '@/z/function/$t.js'
const $t = str => str
const state = {
	city: {},
	wz: {},
	pt: [
		$t("免费WIFI"),
		$t("空调休息室"),
		$t("按摩室"),
		$t("便利店"),
		$t("洗车"),
		$t("饮用水"),
		$t("卫生间"),
		$t("餐馆"),
		$t("自动售货机"),
		$t("地锁"),
	],
	CcdSJEnddatas: {},
	kfutel: "400-8800-684",
	kfuteltest: "4008800684"
};
const getters = {};
const mutations = {
	setCity(state, city) {
		state.city = city;
	},
	setWz(state, wz) {
		// console.log(wz, "wz");
		state.wz = wz;
	},
	setCcdSJEnddatas(state, ddh) {
		state.CcdSJEnddatas[ddh] = true;
	}
};
const actions = {
	async getLocation({
		commit
	}) {
		let wz = await uni.$z.getLocation();
		console.log('wz', wz);
		// #ifndef APP
		let wz2 = uni.$z.gps.bd09togcj02(wz.lng, wz.lat);
		let data = await uni.$z.request({
			url: `https://restapi.amap.com/v3/geocode/regeo?key=517d8820e2d55ee1b86b5b0f080fc405&output=JSON&location=${wz2[0]},${wz2[1]}`,
			method: "post",
		})
		let city = data.regeocode.addressComponent.city
		let cityjsxs = cityjs.flat();
		let r = cityjsxs.find((e) => {
			return e.label == city;
		});
		if (r) {
			console.log('r', r)
			commit("setCity", r);
		}
		// #endif

		commit("setWz", wz);
	},
	setCityfn({
		commit
	}, AreaCode) {
		let cityjsxs = cityjs.flat();
		let r = cityjsxs.find((e) => {
			return e.value == AreaCode;
		});
		if (r) {
			commit("setCity", r);
		}
	}
};
export default {
	state,
	getters,
	mutations,
	actions,
};